/**
 * @param {number[]} possible
 * @return {number}
 */
var minimumLevels = function(possible) {
  let result = -1
  const length = possible.length
  let leftArr = possible.slice(0, 1)
  let rightArr = possible.slice(1, length)
  let leftSum = 0
  let rightSum = 0

  leftArr.forEach(value => {
    leftSum += value === 0 ? -1 : value
  })

  rightArr.forEach(value => {
    rightSum += value === 0 ? -1 : value
  })

  if (leftSum > rightSum) {
    return leftArr.length
  }

  for(let i = 1; i < length - 1; i++) {
    let num = possible[i] === 0 ? -1 : possible[i]
    leftSum += num
    rightSum -= num

    if (leftSum > rightSum) {
      return i + 1
    }
  }


  return result
};